/*
 * Copyright (c) 2007 jNetX.
 * http://www.jnetx.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * jNetX. You shall not disclose such Confidential Information and
 * shall use it only in accordance with the terms of the license
 * agreement you entered into with jNetX.
 *
 * $Id$
 */
package com.jnetx.javax.sip.header;

import junit.framework.TestCase;

import javax.sip.header.AuthenticationInfoHeader;
import java.text.ParseException;

/**
 * @author <a href="mailto:dparhonin@jnetx.ru">Dmitry Parhonin</a>
 * @version $Revision$
 */
public class AuthenticationInfoHeaderParserTest extends TestCase {
    public AuthenticationInfoHeaderParserTest(String name) {
        super(name);
    }

    public void test() {
        final byte[] data = "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\",qop=auth-int, rspauth=\"AABBCC9900\",cnonce=\"DDEE66FF\", nc=97".getBytes();
        final AuthenticationInfoHeaderParser parser = new AuthenticationInfoHeaderParser();
        AuthenticationInfoHeader[] headers;
        try {
            headers = parser.parse(data, 20, data.length);
        } catch (ParseException e) {
            fail(e.getMessage());
            return;
        }
        assertNotNull("The result is null!", headers);
        assertEquals("The length of the result is wrong!", 1, headers.length);
        assertEquals("The next nonce is wrong!", "47364c23432d2e131a5fb210812c", headers[0].getNextNonce());
        assertEquals("The qop is wrong!", "auth-int", headers[0].getQop());
        assertEquals("The rspauth is wrong!", "AABBCC9900", headers[0].getResponse());
        assertEquals("The cnonce is wrong!", "DDEE66FF", headers[0].getCNonce());
        assertEquals("The nc is wrong!", 97, headers[0].getNonceCount());
        assertEquals("The string representation is wrong!", "Authentication-Info: nextnonce=\"47364c23432d2e131a5fb210812c\",cnonce=\"DDEE66FF\",nc=97,qop=auth-int,rspauth=\"AABBCC9900\"", headers[0].toString());
    }
}
